<?php

class Session_lite
{	
	var $group;
	
	function Session_lite($name='')
	{			
		if ($name)
			$this->create($name);
	}
	
	function create($name)
	{
		if (empty($name)) return;
		$this->group = $name;
		
		global $CI;
		$a = $CI->session->userdata($this->group);				
		if(empty($a))
		{		
			$CI->session->set_userdata($this->group, array());
		} 	
	}
	
	function add( $name, $value )
	{	
		if (empty($this->group)) return;
		if (empty($name)) return;
			
		global $CI;
		$a = $CI->session->userdata($this->group);		
		$a[$name] = $value; 	
		$CI->session->set_userdata($this->group, $a);
	} 
	
	function load( $name )
	{
		if (empty($this->group)) return;
		if (empty($name)) return;
		global $CI;
		$a = $CI->session->userdata($this->group);
		return isset($a[$name])?$a[$name]:null; 
	}
	
	function is_empty()
	{
		if (empty($this->group)) return true;
		
		global $CI;
		$a = $CI->session->userdata($this->group);		
		return !$a || (is_array($a) && !count($a));
	}
	
	function clean()
	{
		if (empty($this->group)) return;
		global $CI;
		$CI->session->unset_userdata($this->group);		
	}
}

?>
